<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../../static/js/jquery.js"></script>
    <script type="text/javascript">

    </script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>仓库管理</li>
        <li>仓库管理</li>
        <li>基本内容</li>
    </ul>
</div>
<div class="rightinfo">
    <form action="" method="post">
        <ul class="tools">
            <li>仓库名称:
                <input maxlength="30" type="text" id="storageName"/>
            </li>
            <li> 所属区域：
                <select class="province" name="provinceId" onchange="provinceChange()">
<!--                    <option value="">-请选区域-</option>-->
<!--                    <option value="江西">江西</option>-->
<!--                    <option value="广东">广东</option>-->
<!--                    <option value="湖南">湖南</option>-->
                </select>
                <select class="city">
                    <option value="">-请选城市-</option>
<!--                    <option value="南昌">南昌</option>-->
<!--                    <option value="东莞">东莞</option>-->
<!--                    <option value="长沙">长沙</option>-->
                </select>
            </li>
            <li class="subBut" id="serchBtn"><img src="../../../static/images/t06.png"/>查询</li>
            <a href="/storage/storage/storageAddPage">
                <li class="subBut" id="addBtn"><img src="../../../static/images/t01.png"/>添加</li>
            </a>
        </ul>
        <table class="tablelist" id="tablelist">
            <thead>
            <tr>
                <th>序号</th>
                <th>仓库名称</th>
                <th>负责人</th>
                <th>联系电话</th>
                <th>所属区域</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>创建人</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <!--            <tr>-->
            <!--                <td>1</td>-->
            <!--                <td>南京21号仓库</td>-->
            <!--                <td>朱元璋</td>-->
            <!--                <td>17370899727</td>-->
            <!--                <td>江苏南京</td>-->
            <!--                <td>可用</td>-->
            <!--                <td>2013-09-09 15:05:05</td>-->
            <!--                <td>马云</td>-->
            <!--                <td>-->
            <!--                    <a href="storageView.html" class="tablelink">查看详情</a>-->
            <!--                    <a href="storageUpdate.html" class="tablelink">修改</a>-->
            <!--                    <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
            <!--                </td>-->
            <!--            </tr>-->
            <!--            <tr>-->
            <!--                <td>2</td>-->
            <!--                <td>武汉71号仓库</td>-->
            <!--                <td>周瑜</td>-->
            <!--                <td>17370899727</td>-->
            <!--                <td>湖北武汉</td>-->
            <!--                <td>不可用</td>-->
            <!--                <td>2013-09-09 15:05:05</td>-->
            <!--                <td>马化腾</td>-->
            <!--                <td>-->
            <!--                    <a href="storageView.html" class="tablelink">查看详情</a>-->
            <!--                    <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
            <!--                </td>-->
            <!--            </tr>-->
            <!--            <tr>-->
            <!--                <td>3</td>-->
            <!--                <td>南京21号仓库</td>-->
            <!--                <td>朱元璋</td>-->
            <!--                <td>17370899727</td>-->
            <!--                <td>江苏南京</td>-->
            <!--                <td>可用</td>-->
            <!--                <td>2013-09-09 15:05:05</td>-->
            <!--                <td>马云</td>-->
            <!--                <td>-->
            <!--                    <a href="storageView.html" class="tablelink">查看详情</a>-->
            <!--                    <a href="storageUpdate.html" class="tablelink">修改</a>-->
            <!--                    <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
            <!--                </td>-->
            <!--            </tr>-->
            <!--            <tr>-->
            <!--                <td>4</td>-->
            <!--                <td>武汉71号仓库</td>-->
            <!--                <td>周瑜</td>-->
            <!--                <td>17370899727</td>-->
            <!--                <td>湖北武汉</td>-->
            <!--                <td>不可用</td>-->
            <!--                <td>2013-09-09 15:05:05</td>-->
            <!--                <td>马化腾</td>-->
            <!--                <td>-->
            <!--                    <a href="storageView.html" class="tablelink">查看详情</a>-->
            <!--                    <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
            <!--                </td>-->
            <!--            </tr>-->
            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue" id="total">1256</i>条记录，当前显示第&nbsp;<i class="blue"
                                                                                       id="current">2&nbsp;</i>页
            </div>
            <ul class="paginList" id="paginList">
                <!--                <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;">1</a></li>-->
                <!--                <li class="paginItem current"><a href="javascript:;">2</a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;">3</a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;">4</a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;">5</a></li>-->
                <!--                <li class="paginItem more"><a href="javascript:;">...</a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;">10</a></li>-->
                <!--                <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
            </ul>
        </div>
    </form>
    <!-- 提示框 -->
    <div id="tip" class="tip">
        <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
        <div class="tipinfo"><span><img src="../../../static/images/ticon.png"/></span>
            <div class="tipright">
                <p></p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite></div>
        </div>
        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定" onclick="updatestate()"/>
            &nbsp;
            <input name="" type="button" class="cancel" value="取消" onclick="tipClose()"/>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
<script>
    var isSerch = false;
    $(function () {
        getAddressInfo();
        loadstorages(1);
        // 搜索点击事件
        $("#serchBtn").on("click", function () {
            isSerch = true;
            // alert($('.city').val());
            // alert($('.province').val())
            loadstorages(1);
        })

        // // 添加点击事件
        // $("#addBtn").on("click", function () {
        //     // alert(2);
        // })
    });

    //全局信息
    window.datas = {
        //查询条件
        conditionInfo: {
            pageNum: "1",
            pageSize: "4",
            condition: {
                company: ''
            }
        },
        //查询信息
        resultInfo: {},
        //地区信息
        addressInfo:[],
    };
    //获取地区信息
    function getAddressInfo() {
        $.ajax({
            url: "/commonProvince",
            type: "get",
            dataType: "json",
            success: (data) => {
                window.datas.addressInfo = data.data;
                $(".province").html('<option value="">请选择省份</option>')
                window.datas.addressInfo.forEach((item, index) => {
                    $(".province").append(`<option name="${item.id}" value="${item.pname}">${item.pname}</option>`)
                })
            }
        })
    }

    //选择省份之后
    function provinceChange() {
        let addressInfo = datas.addressInfo;
        let city = [];
        let id = $(".province option:selected").attr("name");
        for (let i = 0; i < addressInfo.length; i++) {
            if (addressInfo[i].id == id) {
                city = addressInfo[i].citys;
                break;
            }
        }
        $(".city").html('<option value=""></option>')
        city.forEach((item, index) => {
            $(".city").append(`<option value="${item.cname}">${item.cname}</option>`);
        })

    }

    //加载仓库列表
    function loadstorages(currentPage) {
        let province;
        let city;
        let storageName;
        if (isSerch) {
            province = $('.province').val();
            city = $('.city').val();
            storageName = $('#storageName').val();
        }

        let nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
        let nowUserID = nowUser.uid;
        //跳转servlet路径、传入参数、获取返回值——页面片段并显示！
        $.ajax({
            type: "GET",//请求类型
            url: "/Warehouse/WarehousePage",//请求的url
            data: {
                province: province,
                city: city,
                cNamelike: storageName,
                userID:nowUserID,
                pageNum: currentPage,
                pageSize: 4
            },//请求参数
            dataType: "json",//ajax接口（请求url）返回的数据类型
            success: function (pb) {
                pb = pb.data;
                $("#total").html(pb.totalCount)
                $("#current").html(pb.pageNum)
                //1.展示分页页码
                var lis = "";
                //上一页
                var beforenum = pb.pageNum - 1;
                if (beforenum <= 0) {
                    beforenum = 1;
                }
                var beforePage = '<li class="paginItem" onclick="loadstorages(' + beforenum + ')"><a href="javascript:;"><span class="pagepre"></span></a></li>';
                lis += beforePage;

                // 1,2,3,4...
                // 定义开始位置begin,结束位置 end
                var begin; // 开始位置
                var end; //  结束位置

                //要显示6个页码
                if (pb.totalPage < 6) {
                    //总页码不够10页
                    begin = 1;
                    end = pb.totalPage;
                } else {
                    //总页码超过6页
                    begin = pb.pageNum - 3;
                    end = pb.pageNum + 2;
                    //2.如果前边不够3个，后边补齐6个
                    if (begin < 1) {
                        begin = 1;
                        end = begin + 5;
                    }
                    //3.如果后边不足2个，前边补齐6个
                    if (end > pb.totalPage) {
                        end = pb.totalPage;
                        begin = end - 5;
                    }
                }
                for (var i = begin; i <= end; i++) {
                    var li;
                    //判断当前页码是否等于i
                    if (pb.pageNum == i) {
                        li = '<li class="paginItem current" onclick="loadstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
                    } else {
                        //创建页码的li
                        li = '<li class="paginItem" onclick="loadstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
                    }
                    //拼接字符串，加入页面中
                    lis += li;
                }

                //下一页
                var nextnum = pb.pageNum + 1;
                if (nextnum > pb.totalPage) {
                    nextnum = pb.totalPage;
                }
                var nextPage = '<li class="paginItem" onclick="loadstorages(' + nextnum + ')"><a href="javascript:;"><span class="pagenxt"></span></a></li>';
                lis += nextPage;

                $("#paginList").html(lis);//显示

                // 3.显示当前页列表
                var storage_lis = '';
                for (var i = 0; i < pb.data.length; i++) {

                    var storage = pb.data[i];//该页路线数据显示        showOrder(id)
                    let states = "";
                    let action = "";
                    if (storage.state == "1") {
                        states = "可用";//启用后才可  注销 与 修改
                        action =
                            '<a href="/storage/storage/storageUpdate?id='+storage.id+'" class="tablelink">修改</a>&nbsp;&nbsp;' +
                            '<a href="javascript:void(0)" class="tablelink" onClick="updateNowState('+storage.state+','+storage.id+')">注销</a>';
                    } else {
                        states = "不可用";//注销后   恢复
                        action =
                            '<a href="javascript:void(0)" class="tablelink" onClick="updateNowState('+storage.state+','+storage.id+')">恢复</a>';
                    }

                    var storageli =
                        '<tr>' +
                        '<td>' +
                        '<span>' + ((pb.pageNum - 1) * 4 + i + 1) + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.cname + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.usre + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.phone + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.caddress + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + states + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.creationTime + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<span>' + storage.users + '</span>' +
                        '</td>' +
                        '<td>' +
                        '<a href="/storage/storage/storageView?id='+storage.id+'" class="tablelink">查看详情</a>&nbsp;&nbsp;'
                        + action +
                        '</td>' +
                        '</tr>';
                    storage_lis += storageli;
                }
                $("#tablelist tbody").html(storage_lis);

                // //仓库详情
                // $(".viewOrder").on("click", function () {
                //     //将被绑定的元素（a）转换成jquery对象，可以使用jquery方法
                //     var obj = $(this);
                //     window.location.href = path + "/view/storageview.jsp?storageid=" + obj.attr("storageid");
                // });
                //
                // //仓库修改
                // $(".modifyOrder").on("click", function () {
                //     var obj = $(this);
                //     window.location.href = path + "/view/storagemodify.jsp?storageid=" + obj.attr("storageid");
                // });
            }
        })
    }


    function tipOpen(content) {
        $(".tipright p").text(content);
        $("#tip").fadeIn(200);
    }

    function tipClose() {
        $("#tip").fadeOut(200);
    }

    var nowItemstate='';
    var nowid;
    function updateNowState(state,id){
        tipOpen("是否确认更新状态？")
        // alert("state"+state)
        nowItemstate=state;
        nowid=id;
    }

    function updatestate() {
        updateState(nowItemstate,nowid);
        tipClose();
    }

    //更新状态  注销不启用  恢复启用
    function updateState(newState,nowid) {
        // alert("newState:"+newState)
        if (newState=='0') newState='1';
        else newState='0';
        $.ajax({
            url: "/Warehouse/updateWarehouseState",
            type: "get",
            dataType: "json",
            data:{
                state:newState,
                id:nowid
            },
            success: (data) => {
                alert(data.msg);
                loadstorages(1)
            }
        })
    }

</script>
</body>
</html>
